package put.cs.two.hied.netflix;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class CreateTestResultFile {

	/**
	 * @param args
	 * @throws IOException 
	 */
	
	private static int randomInt(int min, int max) {
		return (int) (Math.random() * (max - min + 1) ) + min;
	}
	
	private static void createTestResult(File patternResult) throws IOException {
		BufferedReader in = null;
		BufferedWriter out = null;
		String line;
		try {
			in = new BufferedReader(new FileReader(patternResult.getCanonicalPath()));
			out = new BufferedWriter(new FileWriter("/home/ivas/netflix/orginal_data/sampleResult1.txt"));
			int fileIter = 0;
			while ((line = in.readLine()) != null) {
	        	fileIter++;
	        	if(fileIter % 50 == 0) {
	        		System.out.println(" > parsing... line " + fileIter);
	        	}
	            if (!line.contains(":")) {
	            	String[] words = line.split(",");
	            	String userId = words[0];
	            	int rating = Integer.parseInt(words[1]);
	            	double isReplaceToNew = Math.random();
	            	if(isReplaceToNew > 0.5) {
	            		rating = randomInt(1,5);
	            	}
	            	out.write(userId + "," + rating + "\n");
	            } else {
	            	out.write(line + "\n");
	            }
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			in.close();
	        out.close();
		}
		
	}
	
	public static void main(String[] args) {
		try {
			createTestResult(new File("/home/ivas/netflix/orginal_data/copy/qualifierResult2.txt"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
